<?php
/**
 * @author shutyuka@gmail.com
 * @modified 2011-02-20
 */
class Service{
	
	static public $FLAG_INACTIVE = 0;
	
	static public $STATUS_UNACTIVE = 10;
	
	static public $TABLE_NAME="services";

	static public function Create($service) {
		$service['create_time'] = time();
		$service['id'] = DB::Insert(self::$TABLE_NAME, $service);
		
		return $service['id'];
	}
	
	static public function Update($service) {
		Table::UpdateCache(self::$TABLE_NAME, $service['id'], $service);
		
		return ;
	}
	
	static public function GetAll(){
		$oc = array( 
			'activity' => self::$FLAG_INACTIVE
			);
		$allShops = DB::LimitQuery(self::$TABLE_NAME, array(
				'condition' => $oc,
				'order' => 'ORDER BY id ASC'
				));
		return $allShops;
	}
	
	static public function GetAllByShopId($shopId){
		$oc = array( 
			'activity' => self::$FLAG_INACTIVE,
			'shop_id' => $shopId
			);
		$allShops = DB::LimitQuery(self::$TABLE_NAME, array(
				'condition' => $oc,
				'order' => 'ORDER BY id ASC'
				));
		return $allShops;
	}
	
	static public function GetById($id) {
		if (!$id) return array();
		return DB::GetTableRow(self::$TABLE_NAME, array('id' => $id));
	}

	static public function SetServiceUnactive($serviceId) {
		if (!$serviceId) 
			return array();
		Table::UpdateCache(self::$TABLE_NAME, $serviceId, array(
			'activity' => self::$STATUS_UNACTIVE)
		);
		return ;
	}
	
	
	static public function SetServiceInActive($serviceId) {
		if (!$serviceId) 
			return array();
		Table::UpdateCache(self::$TABLE_NAME, $serviceId, array(
			'activity' => self::$FLAG_INACTIVE)
		);
		return ;
	}
	
static public function DeleteById($id, $opId){
				
		$sql = "delete from ".self::$TABLE_NAME." where id=$id" ;
		//Logs::setLog("new sql is || $sql ||");
		return DB::GetQueryResult($sql, false);
	}
	
}
